//
//  WFCollectionVC.m
//  谷居
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 刘万方. All rights reserved.
//

#import "WFCollectionVC.h"

#import "WFSegment.h"

#import "WFScrollView.h"

#import "Masonry.h"
#import "WFTableView.h"
#import "WFCaseCell.h"
#import "WFSaveTool.h"
#import "WFUIView.h"
@interface WFCollectionVC ()
<
UITableViewDataSource,
UITableViewDelegate,
WFCaseCellDelegate
>

@property (nonatomic, retain) WFSegment *segment;

@property (nonatomic, retain) WFUIView *segBaseView; /** segment 下方view. */

@property (nonatomic, retain) WFScrollView *baseScrollView; /** 底层的scrollview. */

@property (nonatomic, retain) WFTableView *likeTableView; /** 喜欢tableView. */



@end

@implementation WFCollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    /** 创建scrollview. */
    [self createScrollView];
    
    /** 创建segmentView. */
    [self createSegment];
    
    /** 创建喜欢tableVeiw. */
    [self createLikeTableView];
    
    /**创建数据. */
}


#pragma mark - 创建segmentView
- (void)createSegment {
    _segBaseView = [[WFUIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    [self.view addSubview:_segBaseView];
    [_segBaseView release];
    _segBaseView.backgroundColor = [UIColor grayColor];
    
    _segment = [[WFSegment alloc]initWithItems:@[@"案例", @"攻略"]];
    [_segBaseView addSubview:_segment];
    _segment.frame = CGRectMake(10, 5, SCREEN_WIDTH - 40, 30);
    [_segment release];
    
    _segment.selectedSegmentIndex = 0;
    
    [_segment addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventValueChanged];
    
    
    
}

/** segment的点击方法. */
- (void)changeView:(WFSegment *)segment {
    if (segment.selectedSegmentIndex == 0) {
        _baseScrollView.contentOffset = CGPointMake(0, 0);
    } else {
        _baseScrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
    }
}



#pragma mark - 创建Scrollview
- (void)createScrollView {
    _baseScrollView = [[WFScrollView alloc] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, SCREEN_HEIGHT - 40 -64 - 48)];
    [self.view addSubview:_baseScrollView];
    [_baseScrollView release];
    _baseScrollView.contentSize = CGSizeMake(_baseScrollView.frame.size.width * 2, 0);
    _baseScrollView.pagingEnabled = YES;
    _baseScrollView.scrollEnabled = NO;
    _baseScrollView.layer.masksToBounds = NO;
    
}


#pragma mark - 创建likeTableView
- (void)createLikeTableView {
    _likeTableView = [[WFTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 40 - 48) style:UITableViewStylePlain];
    [_baseScrollView addSubview:_likeTableView];
    [_likeTableView release];
    _likeTableView.rowHeight = 240;
    _likeTableView.delegate = self;
    _likeTableView.dataSource = self;
    [_likeTableView registerClass:[WFCaseCell class] forCellReuseIdentifier:@"collect"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [WFSaveTool getLikeArray].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WFCaseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"collect" forIndexPath:indexPath];
    cell.projectModel = [WFSaveTool getLikeArray][indexPath.row];
    NSLog(@"%@", cell.projectModel);
    cell.styleCell = 1;
    cell.delegate = self;
    return cell;
}

- (void)tableViewReloadData {
    [_likeTableView reloadData];
}

- (void)dealloc {
    [super dealloc];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
